<!DOCTYPE html>
<html>
<head>
    <title>攻略系列</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/strategyCatalogs.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css"/>
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script src="js/common.js"></script>
    <script>
        $(function () {
            //获取上一页面传入的攻略id，发送请求获取攻略目录和攻略文章
            var params=getParams();

            //根据目录id获取骡友点评标签
            $.get("/strategies/"+params.id+"/tags",{pageSize:0},function (data) {
                $(".tag").renderValues(data)
            });


            if (params.id) {
                //根据攻略id获取攻略信息
                $.get("/strategies/"+params.id,function (data) {
                    //渲染获取到的大攻略信息
                    $(".strategies .title").html(data.title);
                });
                //根据攻略id获取攻略分类和攻略文章
                $.get("/strategies/"+params.id+"/catalogs",function (data) {
                    //渲染获取到的攻略分类和文章信息
                    var index = 1;
                    $(".catalogs").renderValues(data,{
                        getHref:getHref,
                        getName:function (item,value) {
                            var temp = "";
                            if (index < 10) {
                                temp = "0" + index++ +"/"+ value;
                            }else {
                                temp = index++ + "/"+value;
                            }
                            $(item).html(temp);
                        }
                    });
                });

            }

            //根据大攻略id获取评论数据集合
            //发送请求获取所有的游记信息
            var currentPage = 1;
            //定义总页数
            var pages;
            //定义游记信息
            var travelData=[];
            //定义查询状态
            var loading = false;
            function query() {
                if (loading) {
                    return;
                }
                loading = true;
                $.get("/strategies/"+params.id+"/comments",{currentPage:currentPage},function (data) {
                    pages = data.pages;
                    $.merge(travelData, data.list);
                    //拿到信息使用jrender渲染到allTravels
                    $("#comment").renderValues({list:travelData},{
                        getHref:getHref,
                        getStar:function (item,value) {
                            var temp ="";
                            for (var i=0;i<value;i++) {
                                temp += '<i class="fa fa-star"></i>';
                            }
                            for(var i=0;i<5-value;i++) {
                                temp += '<i class="fa fa-star-o"></i>';
                            }
                            $(item).html(temp);
                        }
                    });
                    loading = false;
                    currentPage++;

                    //绑定图片点击事件，显示大图
                    $("#comment .comment-img img").click(function () {
                        $(document).dialog({
                            titleShow: false,
                            overlayClose: true,
                            content: '<img  src="'+$(this).attr("src")+'"width="100%">',
                        });
                    });
                });
            }
            //第一次查询
            query();
            //绑定滚动事件
            $(window).scroll(function () {
                if ($(window).height()+$(document).scrollTop()+0.5>=$(document).height()) {
                    //第二次查询
                    if(currentPage<=pages) {
                        query();
                    }else {
                        $(document).dialog({
                            type : 'notice',
                            infoText: '亲，已经到底了，不要再划拉',
                            autoClose: 2500,
                            position: 'bottom'  // center: 居中; bottom: 底部
                        });
                    }
                }
            });
            //绑定点评点击事件，跳转点评页面，携带攻略目录id
            $("#commentBtn").click(function () {
                window.location.href = "/mine/addComment.html?id="+params.id;
            });
        });
    </script>

</head>

<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col-2">
            <a href="javascript:history.go(-1);">
                <span><i class="fa fa-chevron-left fa-2x"></i></span>
            </a>
        </div>
        <div class="col-10">
            <div class="input-group-sm search">
                <input class="form-control searchBtn" placeholder="搜索旅行攻略">
            </div>
        </div>
    </div>
</div>

<div class="container strategies">
    <h5 class="title"></h5>
    <small><span>0</span>人阅读过此攻略</small>
    <div class="focus">
        <i class="fa fa-heart"><span> 0</span> 收藏</i>
        <i class="fa fa-thumbs-up"><span> 0</span> 点赞</i>
        <button class="btn">想去</button>
        <button class="btn">去过</button>
    </div>
</div>
<ul class="nav nav-pills nav-justified border border-left-0 border-top-0 border-right-0" id="pills-tab">
    <li class="nav-item ">
        <a class="nav-link active" id="pills-catalog-tab" data-toggle="pill" href="#pills-catalog">
            <span>攻略目录</span>
        </a>
    </li>
    <li class="nav-item">
        <a class="nav-link " id="pills-comment-tab" data-toggle="pill" href="#pills-comment">
            <span>骡友点评</span>
        </a>
    </li>
</ul>
<div class="tab-content " id="pills-tabContent">
    <div class="tab-pane fade show active" id="pills-catalog">
        <div class="container hot">
            <h6>大家都在看</h6>
            <div>
                <a href="travelContent.html">
                    <button class="btn">上下九</button>
                </a><a href="travelContent.html">
                <button class="btn">入住长隆熊猫酒店，天天都是儿童节</button>
            </a><a href="travelContent.html">
                <button class="btn">飞到羊城，只为一场最地道的早茶之旅</button>
            </a></div>
        </div>
        <div class="catalogs">
            <div render-loop="list">
                <div class="container detail">
                    <h6 render-key="list.name" render-fun="getName"></h6>
                    <div render-loop="list.strategyDetailList">
                        <a data-url="strategyDetails.html" render-fun="getHref" render-key="list.strategyDetailList.id">
                            <button class="btn" render-html="list.strategyDetailList.title"></button>
                        </a>
                    </div>
                </div>
            </div>
        </div>

    </div>
    <div class="tab-pane fade " id="pills-comment">

        <div class="container tag">
            <h6>骡友标签</h6>
            <div render-loop="list">
                    <span render-html="list.name"></span>
            </div>
        </div>
        <hr>

        <div id="comment">
            <div render-loop="list">
                <div class="container row comment">
                    <!--评论人头像-->
                    <div class="col-2 comment-head">
                        <a data-url="userProfiles.html" render-fun="getHref" render-key="list.user.id">
                            <img class="rounded-circle" render-src="list.user.headImgUrl">
                        </a>
                    </div>
                    <div class="col comment-right">
                        <p class="authorName"><span render-html="list.user.nickName"></span></p>
                        <!--星星-->
                        <span class="comment-star"  render-key="list.starNum" render-fun="getStar" >
                        </span>
                        <span class="comment-date" render-html="list.createTime"></span>
                        <!--评论内容-->
                        <div class="comment-content">
                            <a href="strategyComment.html" >
                                <p render-html="list.content"></p>
                            </a>
                        </div>
                        <!--评论图片-->
                        <ul class="comment-img" render-loop="list.imgArr">
                            <li>
                                <img  render-src="list.imgArr.self">
                            </li>
                        </ul>
                        <!--评论下脚-->
                        <div class="d-flex icon">
                            <a href="strategyComment.html" >
                                <i class="fa  fa-commenting-o " style="margin-right: 10px"> 评论 </i>
                                <i class="fa fa-thumbs-o-up" > <span >0</span> </i>
                            </a>
                        </div>

                    </div>
                </div>

                </div>
            </div>
        </div>

    </div>
</div>

<div class="operation">
    <button class="btn">加入旅行单</button>
    <button class="btn" id="commentBtn">点评</button>
</div>


</body>
</html>